const connect = require('connect');
const serveFavicon = require('serve-favicon');
const expressSession = require('express-session');
const redis = require('redis');
const connectRedis = require('connect-redis');
const path = require('path');

const favicon = path.join(__dirname, 'favicon.ico');

const RedisStroe = connectRedis(expressSession);
const redisClient = redis.createClient();

const app = connect()
  .use(serveFavicon(favicon))
  .use(
    expressSession({
      secret: 'keyboard cat',
      store: new RedisStroe({ client: redisClient, prefix: 'sid' })
    })
  )
  .use(function (req, res, next) {
    const cookie = req.session.cookie;
    res.write(
      `
<p>expires in: ${cookie.maxAge / 1000}</p>
<p>httpOnly: ${cookie.httpOnly}</p>
<p>path: ${cookie.path}</p>
<p>domain: ${cookie.domain}</p>
<p>secure: ${cookie.secure}</p>
      `
    );
    res.end();
  });

app.listen(3000, () => {
  console.log('http://localhost:3000');
});
